package org.thoughtworks.selenium.flex.util;

import org.thoughtworks.selenium.flex.ui.AutomationIdMap;

import java.util.Map;
import java.util.StringTokenizer;

public class FlexUtil {
    
    private FlexUtil() {
    }

    public static AutomationIdMap createAutomationIdMap(String commaSeperatedLocatorValues) {
        AutomationIdMap<String, String> automationIdMap = new AutomationIdMap<String, String>();
        StringTokenizer commaTokenizer = new StringTokenizer(commaSeperatedLocatorValues, ",");
        while (commaTokenizer.hasMoreTokens()) {
            String locatorPart = commaTokenizer.nextToken();
            StringTokenizer keyValue = new StringTokenizer(locatorPart, "=");
            if (keyValue.hasMoreTokens()) {
                automationIdMap.put(keyValue.nextToken(), keyValue.nextToken());
            }
        }

        return automationIdMap;
    }

    public static AutomationIdMap createAutomationIdMap(Map locatorValuesAsMap) {
        AutomationIdMap<String, String> automationIdMap = new AutomationIdMap<String, String>();
        automationIdMap.putAll(locatorValuesAsMap);
        return automationIdMap;
    }
}
